package service

import (
	"singo/model"
	"singo/serializer"
)

// DemandDeleteService 删除需求的服务
type DemandDeleteService struct {
}

// DemandDelete 删除需求
func (service *DemandDeleteService) DemandDelete(uid string) serializer.Response {
	var demand model.Demand
	err := model.DB.First(&demand, "uid = ?", uid).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "需求不存在",
			Error:  err.Error(),
		}
	}

	err = model.DB.Delete(&demand).Error
	if err != nil {
		return serializer.Response{
			Status: 50000,
			Msg:    "需求删除失败",
			Error:  err.Error(),
		}
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
